package top.hzy520.goods.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.hzy520.common.constants.Constants;
import top.hzy520.common.resp.ApiResult;
import top.hzy520.goods.entity.ProductSku;
import top.hzy520.goods.service.GoodsService;
import top.hzy520.goods.vo.CategoryVo;
import top.hzy520.goods.vo.ProductSkuVo;
import top.hzy520.goods.vo.ProductVo;

import java.util.List;
import java.util.Set;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 20:02 2018/6/5
 */
@RequestMapping("/goods")
@RestController
public class GoodsController {
     @Autowired
     @Qualifier("goodsServiceImpl")
    private GoodsService goodsService;
     /**
     *@Author: HouZeYu
     *@Description: 查询分类列表
     *@Date: 20:49 2018/6/5
     */
      @RequestMapping("/categoryList")
     public ApiResult categoryList(){
         List<CategoryVo> cateGoryList=goodsService.categoryList();
         ApiResult apiResult=new ApiResult(Constants.RESP_STATUS_OK,"查询成功");
         apiResult.setData(cateGoryList);
       return apiResult;
     }
     /**
     *@Author: HouZeYu
     *@Description: 查询单个子分类详情
     *@Date: 21:15 2018/6/5
     */
     @RequestMapping("/categoryDetail/{id}")
     public ApiResult CategoryGoodsDetail(@PathVariable("id") Long id){
         ApiResult apiResult=new ApiResult(Constants.RESP_STATUS_OK,"查询成功");
         List<ProductVo> productList=goodsService.goodsCategoryDetail(id);
          apiResult.setData(productList);
         return apiResult;
     }
     /**
     *@Author: HouZeYu
     *@Description: 查询该大分类下所有商品
     *@Date: 18:32 2018/6/6
     */
     @RequestMapping("/categoryAllGoods/{id}")
     public ApiResult categoryAllGoods(@PathVariable("id") Long id){
         ApiResult apiResult=new ApiResult(Constants.RESP_STATUS_OK,"查询成功");
         List<ProductVo> productList=goodsService.categoryAllGoods(id);
         apiResult.setData(productList);
         return apiResult;
     }
     /**
     *@Author: HouZeYu
     *@Description: 查询一个SPU商品详情
     *@Date: 18:47 2018/6/6
     */
     @RequestMapping("/goodsDetail/{id}")
   public ApiResult goodsDetail(@PathVariable("id") Long id){
         ApiResult apiResult=new ApiResult(Constants.RESP_STATUS_OK,"查询成功");
         List<ProductSkuVo> productList=goodsService.goodsDetail(id);
         apiResult.setData(productList);
         return apiResult;
   }
   @RequestMapping("/select")
   public ApiResult<List<ProductSku>> selectGoodsBySkuId(@RequestBody Set<Long> longs){
         ApiResult apiResult=new ApiResult(Constants.RESP_STATUS_OK,"查询成功");
          List<ProductSku> productSkuList=goodsService.selectSku(longs);
          apiResult.setData(productSkuList);
         return apiResult;
   }
}
